{% extends "main/base.html" %}
{% load i18n static main_tag %}
{% block title %}{{ title }}{% endblock %}
{% block this_css %}
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/css/bootstrap-select.min.css' %}">
{% endblock %}
{% block content %}
<section class="panel">
    <div class="panel-body">
        <div class="col-md-9">
            <form class="form-inline" role="form" method="get">
                <div class="form-group">
                    <select name="c" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '所有设备' %}</option>
                        {% for ss in equipment_types %}
                            {% if ss.pk|floatformat:'0' == request.GET.c|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input class="form-control" type="text" name="q" value="{% if request.GET.q %}{{ request.GET.q }}{% endif %}">
                        <span class="input-group-btn"><button class="btn btn-primary" type="submit">搜索</button></span>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-3" align="right">{% if perms.main.add_equipment %}
            <a href="{% url 'main:equipment_create' %}?next={{ request.path }}"><button type="button" class="btn btn-success">{% trans "添加设备" %}</button></a>{% endif %}
        </div>
    </div>
</section>
<section class="panel">
    {% get_current_language as LANGUAGE_CODE %}
    <div class="table-responsive panel-body">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>{% trans '设备编号' %}</th>
                    <th>{% trans '设备中文名' %}</th>
                    <th>{% trans '设备英文名' %}</th>{% if perms.main.view_equipment_basic_price %}
                    <th>{% trans '价格' %}</th>{% endif %}
                    <th>{% trans '设备类型' %}</th>
                    <th>{% trans '图纸/资料' %}</th>
                    <th>{% trans '关联订单' %}</th>
                    <th>{% trans '产品编号' %}</th>
                    <th>{% trans '最后更新' %}</th>
                </tr>
            </thead>
            <tbody>{% for d in page_obj %}
                <tr>
                    <td>{{ d.pk }}</td>
                    <td><a href="{% url 'main:equipment_detail' d.id %}">{{ d.equipment_code }}</a></td>
                    <td>{{ d.equipment_cn }}</td>
                    <td>{{ d.equipment_en }}</td>{% if perms.main.view_equipment_basic_price %}
                    <td>{{ d.basic_price|default_if_none:'' }}</td>{% endif %}
                    <td>{{ d.equipment_type }}</td>
                    <td>
                        {% if d.drawing_en %}<a target="_blank" href="{{ d.drawing_en|qiniu }}">{% trans '英文图纸' %}</a><br>{% endif %}
                        {% if d.file_en %}<a target="_blank" href="{{ d.file_en|qiniu }}">{% trans '英文资料' %}</a><br>{% endif %}
                        {% if d.drawing_cn %}<a target="_blank" href="{{ d.drawing_cn|qiniu }}">{% trans '中文图纸' %}</a><br>{% endif %}
                        {% if d.file_cn %}<a target="_blank" href="{{ d.file_cn|qiniu }}">{% trans '中文资料' %}</a><br>{% endif %}
                        {% if d.file_3d %}<a target="_blank" href="{{ d.file_3d|qiniu }}">{% trans '3D图纸' %}</a>{% endif %}
                    </td>
                    <td><span class="label label-primary pull-right r-activity">{{ d.order_count }}</span></td>
                    <td>{{ d.equipment_code_auto }}</td>
                    <td>{{ d.datetime_updated }}</td>
                </tr>{% endfor %}
            </tbody>
        </table>
        <div align="right">
            {% include 'main/tablenav.html' %}
        </div>
    </div>
</section>
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-select.min.js' %}"></script>
{% endblock %}